<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="file" id="file" accept="image/png,image/jpeg" />
    <img src="" alt="" id="image" />
  </body>
  <script>
    let myfile = document.querySelector("#file");
    myfile.onchange = function () {
      let file = myfile.files[0];
      let newUrl = URL.createObjectURL(file);
      document.querySelector("#image").src = newUrl;
    };
  </script>
</html>
